<%@ page language="java" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<input type="hidden" id="cType" value="<s:property value="cType"/>"/>
<div class="modal-body">
    <div class="row">
            <div class="col-md-12">

            <form id="group_input" class="smart-form" novalidate="novalidate" action="" method="post">
                <input type="hidden" name="keyId" id="keyId" placeholder="请输入编号" value="<s:property value="keyId"/>">
                <header>
                   [群组添加]
                </header>
                <fieldset>
                    <div class="row">
                        <label class="label col col-3">编号</label>
                        <section class="col col-9">
                            <label class="input">
                                <input type="text" name="no" id="no" placeholder="请输入编号" value="<s:property value="group.no"/>">
                            </label>
                        </section>
                    </div>
                    <div class="row">
                        <label class="label col col-3">名称</label>
                        <section class="col col-9">
                            <label class="input">
                                <input name="name" id="name" placeholder="请输入名称"
                                type="text" value="<s:property value="group.name"/>">
                            </label>
                        </section>
                    </div>
                    <div class="row">
                        <label class="label col col-3">描述</label>
                        <section class="col col-9">
                            <label class="input">
                                <input name="description" id="description" placeholder="请输入描述"
                                       type="text" value="<s:property value="group.description"/>">
                            </label>
                        </section>
                    </div>
                    <div class="row">
                        <label class="label col col-3">群组类型</label>
                        <section class="col col-9">
                            <div class="inline-group" >
                                <label class="checkbox">
                                    <input type="checkbox" name="type" value="0001" />
                                    <i></i>用户群组
                                </label>
                                <label class="checkbox">
                                    <input type="checkbox" name="type" value="0010" />
                                    <i></i>部门群组
                                </label>
                                <label class="checkbox">
                                    <input type="checkbox" name="type" value="0100" />
                                    <i></i>职权群组
                                </label>
                            </div>
                        </section>
                    </div>
                    <div class="row" id="type-0001" style="display:none">
                        <label class="label col col-3">
                            <a  href="javascript:void(0);" key="ajax_user_group_list">用户群组</a>
                        </label>
                        <section class="col col-9">
                            <label class="input">
                                <input name="userId" id="userId"
                                       type="hidden" value="<s:iterator id="list" value="gusersSet"><s:property value="#list.id"/>,</s:iterator>">
                                <input  id="userName" placeholder="请选择" disabled
                                       type="text" value="<s:iterator id="list" value="gusersSet"><s:property value="#list.name"/>,</s:iterator>">
                            </label>
                        </section>
                    </div>
                    <div class="row" id="type-0010" style="display:none">
                        <label class="label col col-3">
                            <a  href="javascript:void(0);" key="ajax_depart_group_list">部门群组</a>
                        </label>
                        <section class="col col-9">
                            <label class="input">
                                <input name="groupId" id="groupId"
                                       type="hidden" value="<s:iterator id="list" value="gdepartmentSet"><s:property value="#list.id"/>,</s:iterator>">
                                <input  id="departName" placeholder="请选择" disabled
                                        type="text" value="<s:iterator id="list" value="gdepartmentSet"><s:property value="#list.name"/>,</s:iterator>">
                            </label>
                        </section>
                    </div>
                    <div class="row" id="type-0100" style="display:none">
                        <label class="label col col-3">
                            <a  href="javascript:void(0);" key="ajax_post_group_list">职权群组</a>
                        </label>
                        <section class="col col-9">
                            <label class="input">
                                <input name="powerId" id="powerId"
                                       type="hidden" value="<s:iterator id="list" value="gpowerSet"><s:property value="#list.id"/>,</s:iterator>">
                                <input  id="powerName" placeholder="请选择" disabled
                                        type="text" value="<s:iterator id="list" value="gpowerSet"><s:property value="#list.name"/>,</s:iterator>">
                            </label>
                        </section>
                    </div>
                </fieldset>
            </form>
        </div>
    </div>
</div>
<div class="modal-footer">
	<a href="#ajax!group.action" class="btn btn-primary" id="dialog-group-ok">确定</a>
	<button class="btn" data-dismiss="modal" aria-hidden="true">取消</button>
</div>
<script>
    $("#dialog-group-ok").unbind("click").bind("click",function(){
        var actionUrl = "<%=path%>/com/ajax-group!save.action";
        form_save("group_input",actionUrl);
        gDialog.fClose();
        jQuery("#ajax_group_table").trigger("reloadGrid");
    });

    $("input[name='type']").unbind("click").bind("click",function(){
        var typeValue=$(this).val();
        if($(this).prop("checked")){
            $("#type-"+typeValue).show();
        }
        else{
            $("#type-"+typeValue).hide();
        }
    });

    function initCheckBox(obj){
        var cType=$("input#"+obj).val();
        $("input[name='type']").each(function(i,v){
            var optVal = $(v).val();
            var idx = optVal.indexOf("1");
            var divKey = "#type-"+optVal;
            if(cType!=null && cType.charAt(idx) == "1"){
                $(v).prop("checked",true);
                $(divKey).show();
            }
        });
    };

    $(function(){
       initCheckBox("cType");
    });
</script>

<script>
    $("a[key=ajax_user_group_list]").unbind("click").bind("click",function(){
        ajax_action("ajax-dialog!userDlg.action",{keyIds:$("#userId").val()},{},function(pdata){
            oDialog.open({
                title:"请选择人员",
                data:pdata.data.data,
                callback:function(){
                    var obj =$("#group input:checked");
                    var name = getArrProp(obj,"key");
                    var id = getArrProp(obj,"id");
                    $("#userName").val(name);
                    $("#userId").val(id);
                }
            });
        });
    });
    $("a[key=ajax_depart_group_list]").unbind("click").bind("click",function(){
        ajax_action("ajax-dialog!departDlg.action",{keyIds:$("#groupId").val()},{},function(pdata){
            oDialog.open({
                title:"请选择部门",
                data:pdata.data.data,
                callback:function(){
                    var obj =$("#group input:checked");
                    var name = getArrProp(obj,"key");
                    var id = getArrProp(obj,"id");
                    $("#departName").val(name);
                    $("#groupId").val(id);
                }
            });
        });
    });
    $("a[key=ajax_post_group_list]").unbind("click").bind("click",function(){
        ajax_action("ajax-dialog!powerDlg.action",{keyIds:$("#create_p_selectIds").val()},{},function(pdata){
            oDialog.open({
                title:"请选择职权",
                data:pdata.data.data,
                callback:function(){
                    var obj =$("#group input:checked");
                    var name = getArrProp(obj,"key");
                    var id = getArrProp(obj,"id");
                    $("#powerName").val(name);
                    $("#powerId").val(id);
                }
            });
        });
    });
</script>